﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using YArchitech.Controls;
using YArchitech.Revit;

namespace HYRElectric.Equipment
{
	public partial class DlgLayoutPlanCopySelect : System.Windows.Forms.Form
	{
		public DlgLayoutPlanCopySelect(ref Dictionary<ViewPlan, bool> dictViewCopySet)
		{
			this.InitializeComponent();
			this.m_dictViewCopySet = dictViewCopySet;
		}

		public static string GetViewPlanParentName(ViewPlan viewPlan)
		{
			Parameter parameter = viewPlan.GetParameter("视图分类-父");
			string text = (parameter == null) ? "" : parameter.AsString();
			if (string.IsNullOrEmpty(text))
			{
				parameter = viewPlan.GetParameter(BuiltInParameter.VIEW_DISCIPLINE);
				if (parameter != null)
				{
					text = parameter.AsString();
					if (text.IsEmpty<char>() || text == null)
					{
						text = parameter.AsValueString();
					}
				}
			}
			return text;
		}

		public static string GetViewPlanChildName(ViewPlan viewPlan)
		{
			Parameter parameter = viewPlan.GetParameter("视图分类-子");
			string text = (parameter == null) ? "" : parameter.AsString();
			if (string.IsNullOrEmpty(text))
			{
				parameter = viewPlan.GetParameter("子规程");
				if (parameter != null)
				{
					text = parameter.AsString();
					if (text.IsEmpty<char>() || text == null)
					{
						text = parameter.AsValueString();
					}
				}
			}
			return text;
		}

		private void DlgLayoutPlanCopySelect_Load(object sender, EventArgs e)
		{
			TreeNode treeNode = this.treeViewPlanList.Nodes.Add("选择复制视图");
			string a = "";
			string a2 = "";
			TreeNode treeNode2 = null;
			TreeNode treeNode3 = null;
			foreach (KeyValuePair<ViewPlan, bool> keyValuePair in this.m_dictViewCopySet)
			{
				ViewPlan key = keyValuePair.Key;
				bool value = keyValuePair.Value;
				string viewName = key.ViewName;
				string viewPlanParentName = DlgLayoutPlanCopySelect.GetViewPlanParentName(key);
				string viewPlanChildName = DlgLayoutPlanCopySelect.GetViewPlanChildName(key);
				if (a != viewPlanParentName)
				{
					treeNode3 = treeNode.Nodes.Add(viewPlanParentName);
					treeNode2 = treeNode3.Nodes.Add(viewPlanChildName);
					treeNode2.Nodes.Add(viewName).Tag = key;
					a = viewPlanParentName;
					a2 = viewPlanChildName;
				}
				else
				{
					if (a2 != viewPlanChildName)
					{
						treeNode2 = treeNode3.Nodes.Add(viewPlanChildName);
						a2 = viewPlanChildName;
					}
					treeNode2.Nodes.Add(viewName).Tag = key;
				}
			}
			this.treeViewPlanList.SetCheckStatus(treeNode, true);
			this.treeViewPlanList.ExpandAll();
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.GetSelectInfo(this.treeViewPlanList.Nodes[0]);
		}

		private void GetSelectInfo(TreeNode treeNode)
		{
			if (treeNode.Nodes.Count != 0)
			{
				foreach (object obj in treeNode.Nodes)
				{
					TreeNode treeNode2 = (TreeNode)obj;
					this.GetSelectInfo(treeNode2);
				}
				return;
			}
			ViewPlan viewPlan = treeNode.Tag as ViewPlan;
			if (viewPlan == null)
			{
				return;
			}
			this.m_dictViewCopySet[viewPlan] = treeNode.Checked;
		}

		private Dictionary<ViewPlan, bool> m_dictViewCopySet;
	}
}
